home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.arch.embedded,comp.lang.c
- Path: in2.uu.net!allegra!ulysses!netnews
- From: Phong Vo <kpv@research.att.com>
- Subject: Re: Using malloc of C on embedded system?
- Sender: netnews@ulysses.homer.att.com (Shankar Ishwar)
- Message-ID: <3163E1DB.41C67EA6@research.att.com>
- Date: Thu, 4 Apr 1996 14:51:07 GMT
- Content-Transfer-Encoding: 7bit
- Content-Type: text/plain; charset=us-ascii
- References: <4jml7h$cbc@castor.usc.edu> <4jrndq$ate@kuikka.inet.fi> <4jtbot$o1@Mars.mcs.com>
- Mime-Version: 1.0
- X-Mailer: Mozilla 2.0 (X11; I; SunOS 4.1.2 sun4m)
- Organization: AT&T Bell Laboratories
-
- John Payson wrote:
- >
- > In article <4jrndq$ate@kuikka.inet.fi>,
- > Risto Jokinen <hatrjo@hat-fi.kone.com> wrote:
- > >This mechanism works. random size malloc/free does not work on embedded systems, or
- > >at least it is impossible to debug, and can be VERY slow. fixed size partition pool
- > >manager takes <<50us for malloc/free in any processor.
- >
- > Fixed-size malloc/free is often a good approach if it works; to help it
- > along, however, it's often useful to have a "version" of malloc for odd-
- > sized blocks that will never be freed (allocate a large memory pool for
- > these things and just track the last byte used), and sometimes useful to
- > have several memory pools for different-sized objects.
- >
- Get my Vmalloc package from http://www.research.att.com/orgs/ssr/book/reuse/.
- It allows you to create different regions for allocation based on different
- requirements such as special types of memory or special ways to allocate
- (fixed size objects, objects never freed, etc.).
-
- > As I mentioned in another post, the "binary buddy" system is often a good
- > compromise between internal and external fragmentation in embedded systems.
- > All objects consist of a power-of-two number number of "atoms" [smallest
- > allocatable chunk] and, for simplicity, the "total" number of atoms must
- > be a power of two [if the memory size isn't a power of two, "pre-allocate"
- > the memory that isn't there].
- >
- Before anyone get lulled into this. The binary buddy system is rather wasteful
- of memory unless allocated blocks are luckily closed to powers of two. It is
- designed for time speed-up not for space efficiency. Interested people can look
- up the Vmalloc paper in the 3/96 issue of SP&E which contains a study on SUN
- comparing various malloc implementations using trace data from real programs.
- One of the mallocs is based on the binary buddy system. It runs relatively fast
- in CPU time but typically wastes about 40% of space. The space wastage causes
- it to slow down in some large programs because it ends up spending more system
- time to get raw heap memory. On a time-sharing system with virtual memory,
- guess what the effect will be on swap space and overall system performance.
- On an embedded system with limited memory, the space wastage can be critical.
-